﻿/*----------------------------------------------------------------
// Copyright (C) 2011 上海
// 版权所有。 
//
// 文件名：InstockGroupController
// 文件功能描述：食材入库数据访问层
//
// 
// 创建标识：2012-01-14 王冲
//
// 修改标识：
// 修改描述：
//
//
//----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Routing;
using System.Web.Mvc;
using Model.WaiGaoQiao;
using WaiGaoQiaoWeb.Models;
using WaiGaoQiaoWeb.JsonEntities;
using AutoMapper;

namespace WaiGaoQiaoWeb.Controllers
{
    public class InstockGroupController : InstockController
    {
        // GET: /InstockGroup/

        public ActionResult AddInstockGroup(string ID)
        {
            ViewData["Warehouse"] = GetWarehouse();
            ViewData["Group"] = GetGroup();
            ViewData["Supplier"] = GetSupplier();
            return View();
        }

        //*******************************************************
        //  新建食材明细
        //*******************************************************
        public ActionResult AddInstockDetail(int id, string orderno)
        {
            ViewData["SupplierDetail"] = GetSupplier();
            ViewData["Warehouse"] = GetWarehouse();
            ViewData["Group"] = GetGroup();
            InstockDetailedVM idvm = new InstockDetailedVM();
            if (id == 0)
            {
                idvm.ID = 0;
                idvm.InstockDt = DateTime.Now.Date;//.ToString("yyyy-MM-dd");
                idvm.OrderNo = instockDetailedInfo.BuliderOrderNo();
                idvm.OperatorID = ((LogOnModel)System.Web.HttpContext.Current.Session["user"]).LogName;
            }
            else
            {
                InstockDetailedInfo idinfo = (InstockDetailedInfo)GetOneInstockDetailed(id);
                Mapper.DynamicMap(idinfo, idvm);
            }
            return View(idvm);
        }

        public ActionResult ExportExcel()
        {
            return EContent();
        }

        public ExcelContentResult EContent()
        {
            StringBuilder sBuilder = new StringBuilder();
            sBuilder.Append("<table cellspacing='0' cellpadding='5' rules='all' border='1'>");
            sBuilder.Append("<tr style='font-weight: bold; white-space: nowrap;'>");
            sBuilder.Append("<td>借款日</td>");
            sBuilder.Append("<td>借款合同编号</td>");
            sBuilder.Append("<td>借款人/公司</td>");
            sBuilder.Append("</tr>"); //style='vnd.ms-excel.numberformat:@'
            sBuilder.Append("<tr>");
            sBuilder.Append("<td>20110101</td>");
            sBuilder.Append("<td style='vnd.ms-excel.numberformat:@'>201202020001</td>");
            sBuilder.Append("<td>zhangsan</td>");
            sBuilder.Append("</tr>");
            sBuilder.Append("</table>");
            ExcelContentResult econtent = new ExcelContentResult();
            econtent.Content = sBuilder.ToString();
            econtent.filename = "shicairuk";
            econtent.ContentType = "application/ms-excel";
            econtent.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
            return econtent;
        }
    }
}
